home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.EOFException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Vector;
- import symjava.sql.SQLException;
-
- public final class BinaryInputStream extends InputStream {
- private final int METHOD_getData;
- private final int METHOD_setData = 1;
- private final int METHOD_rewind = 2;
- private RemoteObject proxy;
- private byte[] data;
- private int length;
- private int offset;
- private boolean bClosed;
- private boolean bReadCalled;
-
- public BinaryInputStream(int id, ClientSession session) throws SQLException {
- this.proxy = new RemoteObject("ProxyStream", id, session);
- this.length = 0;
- this.offset = 0;
- this.bClosed = false;
- this.bReadCalled = false;
- this.proxy.invokeMethod(2);
- }
-
- public BinaryInputStream(byte[] b) throws SQLException {
- this.proxy = null;
- this.data = b;
- this.length = b.length;
- this.offset = 0;
- this.bClosed = false;
- this.bReadCalled = true;
- }
-
- public BinaryInputStream(String s) throws SQLException {
- this.proxy = null;
- this.length = s.length();
- this.data = new byte[s.length()];
- s.getBytes(0, s.length() - 1, this.data, 0);
- this.offset = 0;
- this.bClosed = false;
- this.bReadCalled = true;
- }
-
- public void close() throws IOException {
- this.bClosed = true;
- }
-
- public int read() throws IOException {
- if (this.bClosed) {
- return -1;
- } else {
- this.bReadCalled = true;
- if (this.offset >= this.length) {
- try {
- this.data = this.getData();
- this.length = this.data.length;
- if (this.length == 0) {
- this.close();
- return -1;
- }
-
- this.offset = 0;
- } catch (SQLException e) {
- throw new IOException(((Throwable)e).getMessage());
- }
- }
-
- return this.data[this.offset++] & 255;
- }
- }
-
- byte[] getData() throws SQLException {
- byte[] b = new byte[0];
- if (this.proxy == null) {
- return b;
- } else {
- Vector results = this.proxy.invokeMethod(0);
- NetData d = (NetData)results.elementAt(0);
- b = d.getBytes();
- return b;
- }
- }
-
- public int getInt() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getInt();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public short getShort() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getShort();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public boolean getBool() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getBool();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public byte getByte() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getByte();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public long getLong() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getLong();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public float getFloat() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getFloat();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public double getDouble() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
-
- try {
- return d.getDouble();
- } catch (EOFException var2) {
- throw new SQLException("Can't convert data to request format");
- }
- }
-
- public byte[] getBytes() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- NetData d = new NetData(this.data);
- return d.getBytes();
- }
-
- public String getString() throws SQLException {
- if (!this.bReadCalled) {
- try {
- this.read();
- } catch (IOException e) {
- throw new SQLException(((Throwable)e).getMessage());
- }
- }
-
- return new String(this.data, 0, 0, this.data.length);
- }
- }
-